<template>
  <div>
    <div>
      httpprint打印
      <el-button v-print="printOneObj" type="primary" @click="printOne">打印单个pdf</el-button>
      <el-button type="primary" @click="printMore">打印多个pdf</el-button>
    </div>

    <div>
      Lodop打印
      <el-button type="primary" @click="printLodop">打印</el-button>
    </div>

    <div>
      直连electron-hiprint
      <el-button type="primary" @click="electronPrint">打印</el-button>
    </div>

  </div>
</template>

<script lang="ts" setup>
import pdfBase64List from "./res/pdfBase64List.ts";
import { io } from "socket.io-client";
import { hiprint, autoConnect } from "@/components/hiprint";

const printOneObj = {
  asyncUrl(reslove, vue) {
    setTimeout(() => {
      reslove("http://localhost:5173/");
    }, 2000);
  },
  preview: false,
  previewBeforeOpenCallback(vue) {
    console.log("正在加载预览窗口");
  },
  previewOpenCallback(vue) {
    console.log("已经加载完预览窗口");
  },
  beforeOpenCallback(vue) {
    console.log("打开之前");
  },
  openCallback(vue) {
    console.log("执行了打印");
  },
  closeCallback(vue) {
    console.log("关闭了打印工具");
  },
};

const printLodop = () => {
  pdfBase64List.forEach((pdf) => {
    LODOP = getLodop();
    LODOP.PRINT_INIT("测试PDF打印功能");
    LODOP.SET_PRINTER_INDEX(-1);
    LODOP.ADD_PRINT_PDF(0, 0, "100%", "100%", pdf);
    LODOP.PRINT();
  });
};

autoConnect();

const electronPrint = () => {
  //   const socket = io("http://localhost:17521", {
  //   transports: ["websocket"],
  //   auth: {
  //     token: "vue-plugin-hiprint", // 在此处填入你 client 设置的 token，缺省可留空
  //   }
  // })
  let pdfUrlList = [
    "https://ssm.meizhitech.com/pdf/1.pdf",
    "https://ssm.meizhitech.com/pdf/2.pdf",
  ];
  pdfUrlList.forEach((pdfUrl) => {
    hiprint.hiwebSocket.send({ type: "url_pdf", pdf_path: pdfUrl });
  });
};
</script>